/*
*
*	The Gimme ECMAScript Library by Stephen Stchur
*	"Taking the pain out of Javascript!"
*
*	Copyright (c) Microsoft Corporation.  All rights reserved.
*
*	Description:
*	Gimme Utilities Module:	Miscellaneous helper methods that just don't fit anywhere else.
*
*/

Gimme.Util = new function()
{
	this.setTimeout = function(_fn, _milliseconds)
	{
		return DelayInvoke(arguments, false);
	};
	
	this.setInterval = function(_fn, _milliseconds)
	{
		return DelayInvoke(arguments, true);
	};
	
	function DelayInvoke(_args, _repeat)
	{
		var fn = _args[0];
		var milliseconds = _args[1];
		function proxy()
		{
			fn.apply(this, Array.prototype.slice.call(_args, 2));
			if (!_repeat) { fn = null; }
		}
		
		if (_repeat === true)
		{
			// Warning:  this will most likely cause memory leak issues in IE
			// TODO:  create a custom clearInterval function that nulls out the function when its called?
			return window.setInterval(proxy, milliseconds);
		}
		else
		{
			return window.setTimeout(proxy, milliseconds);
		}		
	}
};

